package org.yoyo.classroom.service.impl;

import org.yoyo.classroom.mapper.BookingRuleMapper;
import org.yoyo.classroom.domain.po.BookingRule;
import org.yoyo.classroom.mapper.StudyRoomMapper;
import org.yoyo.classroom.service.BookingRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 预约规则业务逻辑层实现类
 */
@Service
public class BookingRuleServiceImpl implements BookingRuleService {

    @Autowired
    private BookingRuleMapper bookingRuleMapper;
    @Autowired
    private StudyRoomMapper studyRoomMapper;


    /**
     * 根据ID查询预约规则
     * @param id 预约规则ID
     * @return 预约规则对象
     */
    @Override
    public BookingRule getBookingRuleById(Long id) {
        return bookingRuleMapper.selectById(id);
    }

    /**
     * 查询所有预约规则
     * @return 预约规则列表
     */
    @Override
    public List<BookingRule> getAllBookingRules() {
        return bookingRuleMapper.selectAll();
    }

    /**
     * 插入预约规则
     * @param bookingRule 预约规则对象
     * @return 影响的行数
     */
    @Override
    public int addBookingRule(BookingRule bookingRule) {
        return bookingRuleMapper.insert(bookingRule);
    }

    /**
     * 更新预约规则
     * @param bookingRule 预约规则对象
     * @return 影响的行数
     */
    @Override
    public int updateBookingRule(BookingRule bookingRule) {
        return bookingRuleMapper.update(bookingRule);
    }

    /**
     * 删除预约规则（逻辑删除）
     * @param id 预约规则ID
     * @return 影响的行数
     */
    @Override
    public int deleteBookingRule(Long id) {
        return bookingRuleMapper.delete(id);
    }

    @Override
    public BookingRule getBookingRuleByRoomId(Long roomId) {
        return studyRoomMapper.getBookingRuleByRoomId(roomId);
    }
}
